package com.nursing.Dao;

import com.nursing.bean.Nurse;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface NurseDao {
    @Select("SELECT * FROM nurse")
    List<Nurse> getAll();

    @Select("SELECT * FROM nurse WHERE id = #{id}")
    Nurse getById(Integer id);

    @Insert("INSERT INTO nurse (name, gender, age,avatar, phone ,password,created_at) VALUES (#{name}, #{gender}, #{age},#{avatar}, #{phone}, #{password},#{createdAt})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Nurse nurse);

    @Update("UPDATE nurse SET name = #{name},avatar = #{avatar}, gender = #{gender}, age = #{age}, phone = #{phone} ,password = #{password} WHERE id = #{id}")
    void update(Nurse nurse);

    @Delete("DELETE FROM nurse WHERE id = #{id}")
    void delete(Integer id);


    @Insert("INSERT INTO care_task (nurse_id, plan_id,task_details,status,executed_at) VALUES (#{nurseId}, #{taskId},#{taskDetails},#{status},#{executedAt})")
    void bindTask(@Param("nurseId") int nurseId, @Param("plan_id") int planId, @Param("taskDetails") String taskDetails, @Param("status") int status, @Param("executedAt") String executedAt);

    @Select("SELECT * FROM nurse WHERE name = #{name} AND password = #{password}")
    Nurse verify(@Param("name") String phone, @Param("password") String password);

    @Select("SELECT COUNT(*) FROM nurse")
    Integer getCount();

    @Update("UPDATE nurse SET password = #{password} WHERE id = #{id}")
    void changePassword(Nurse nurse);
}